package com.gin.pixiv.response.illustration

import com.fasterxml.jackson.annotation.JsonIgnore
import com.gin.pixiv.response.field.FanRequest
import com.gin.pixiv.response.field.PixivTag
import java.time.ZonedDateTime

/**
 * @author bx002
 * @since 2024/2/18 15:12
 */
class IllustrationDetail : IllustrationBody() {
    /**
     * 收藏数
     */
    var bookmarkCount: Int? = null

    /**
     * 评论数
     */
    var commentCount: Int? = null

    /**
     * 作品描述
     */
    var illustComment: String? = null

    /**
     * pid
     */
    var illustId: Long? = null

    /**
     * 作品标题
     */
    var illustTitle: String? = null

    /**
     * 喜欢数量
     */
    var likeCount: Int? = null

    /**
     * 是否喜欢
     */
    var likeData: Boolean? = null

    /**
     * 作品含有的图片数量
     */
    var pageCount: Int? = null

    /**
     * 约稿信息(如果是约稿作品)
     */
    var request: FanRequest? = null

    /**
     * 标签
     */
    var tags: PixivTag? = null

    /**
     * 图片url
     */
    var urls: Urls? = null

    /**
     * 用户账号
     */
    var userAccount: String? = null

    /**
     * 浏览次数
     */
    var viewCount: Int? = null

    /**
     * 用户的其他作品
     */
    var userIllusts: LinkedHashMap<Long, SimpleIllustration>? = null

    /**
     * 上传时间
     */
    var uploadDate: ZonedDateTime? = null

    /**
     * 全部原图URL
     * @return 全部原图URL
     */
    @JsonIgnore
    fun getOriginalUrls(): List<String>? {
        if (urls?.original == null || pageCount == null) {
            return null
        }
        val originalUrl: String = urls?.original!!
        val urls = ArrayList<String>()
        for (i in 0 until pageCount!!) {
            urls.add(originalUrl.replace("_p0", "_p$i"))
        }
        return urls
    }

    companion object {
        class Urls {
            var mini: String? = null
            var original: String? = null
            var regular: String? = null
            var small: String? = null
            var thumb: String? = null

            val zipUrl: String?
                get() = if (original == null) null else original!!
                    .replace("img-original", "img-zip-ugoira")
                    .replace("_ugoira0.jpg", "_ugoira1920x1080.zip")
                    .replace("_ugoira0.png", "_ugoira1920x1080.zip")

        }
    }
}